home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 101-125 / disk_101 / cirplane / cirplane.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  149 lines

  1. /* CIRPLANE    Circular plane generator for VS3D Version 1.00
  2.  *
  3.  *    Generates a clockwise circular polygon with the specified number
  4.  *    of vertices.  For use "capping" a cylinder or as surface detail.
  5.  *
  6.  *    The resultant circular polygon is resting at ground zero (y=0)
  7.  *    and has a radius of 1 such that (-1 <= x <= 1) and (-1 <= z <= 1)
  8.  *
  9.  *    Use:
  10.  *
  11.  *        CLI> CIRPLANE  filename
  12.  *        VS3D 3DG1 Normalized Circular Plane Generator
  13.  *        Copyright (c) 1987 by Thad Floryan
  14.  *        Number of points (3:200)= <n>
  15.  *        Enter the surface color = <n>
  16.  *
  17.  *    where:    filename is typically "geo/name".  You MUST type the path.
  18.  *        color is that used with the EGG and OCT programs.
  19.  *
  20.  *    Copyright (c) 1987 by Thad Floryan.     9-Aug-1987
  21.  *
  22.  * This program, and the source for it, are copyrighted, and are not to be
  23.  * considered in the public domain.  Never-the-less, this program may be
  24.  * copied magnetically or electronically without any additional permission,
  25.  * provided no charge is requested for the program; the only fees permitted
  26.  * are a moderate copying charge, in the case of magnetic distribution (such
  27.  * as distribution by Fred Fish or Amicus), or any normal BBS charges in the
  28.  * case of an electronic download.  Commercial and other uses are negotiable
  29.  * by contacting me.  Feel welcome to use any part of the source for your
  30.  * personal learning.
  31.  *
  32.  *    Building instructions (Manx Aztec C V3.4b2, with IEEE math):
  33.  *
  34.  *        cc +fi cirplane
  35.  *        ln cirplane -lma -lc
  36.  */
  37.  
  38.  
  39. #include <stdio.h>
  40. #include <functions.h>
  41.  
  42. static double radians      = {6.2831853071795864769};    /* 2 PI */
  43. static double radius      = {1};
  44. static int valid_colors[] = { 0,  1,  2,  4,  6,  7,  8,  9, 10, 12, 14, 15,
  45.                  16, 17, 18, 20, 22, 23, 24, 25, 26, 28, 30, 31,
  46.                  32, 33, 34, 36, 38, 39, 40, 41, 42, 44, 46, 47,
  47.                  48, 49, 50, 52, 54, 55, 56, 57, 58, 60, 62, 63,
  48.                  -1 };
  49.  
  50. main(argc,argv)
  51.    int argc;
  52.    char *argv[];
  53. {
  54.    double sin(), cos();
  55.  
  56.    FILE    *output;
  57.    double step, angle, x, z;
  58.    int i, points, color, abs_color;
  59.    
  60.    printf("VS3D 3DG1 Normalized Circular Plane Generator\n");
  61.    printf("Copyright © 1987 by Thad Floryan\n\n");
  62.  
  63.    if ( argc != 2 ) {
  64.      printf("Generates a circular polygon with the specified number ");
  65.      printf("of vertices for use\ncapping a cylinder or as surface ");
  66.      printf("detail.  The resultant polygon is resting\nat ground zero ");
  67.      printf("(y=0) and radius=1 such that -1 <= x <= 1 and -1 <= z <= 1.\n");
  68.      printf("\nUsage:\tCLI> %s \033[1mfilename\033[0m\n\n", argv[0]);
  69.      printf("where:\t\033[1mfilename\033[0m is typically `geo/name'; ");
  70.      printf("you \033[1mmust\033[0m type the full path name\n\n");
  71.      printf("You will be prompted for the number of points (vertices ");
  72.      printf("of the polygon) and\none color from among those recognized ");
  73.      printf("by `VideoScape 3D'® and its attendant\nsupport programs ");
  74.      printf("(e.g. EGG, OCT).\n\nOther geometry and utility programs ");
  75.      printf("are planned.  Your ideas, suggestions\nand bug reports are ");
  76.      printf("welcome; I can be contacted on the following systems:\n\n");
  77.  
  78.      printf("\tAMIC\tThad Floryan\t707/579-0523 (3/12/24)\n");
  79.      printf("\tAmigaOZ\tThad Floryan\t316/283-9210 (3/12/24)\n");
  80.      printf("\tBBS-HT\tThad Floryan\t408/737-0900 (3/12)\n");
  81.      printf("\t\033[1mBBS-JC\033[0m\tThad Floryan\t415/961-7250 (3/12/24)\n");
  82.      printf("\tFAUG\tThad Floryan\t415/595-2479 (3/12)\n");
  83.      printf("\tTemple\tThad Floryan\t408/241-7802 (3/12/24)\n");
  84.      printf("\tBIX\ttfloryan\tTymnet: `bix'\n");
  85.      printf("\tDELPHI\tTHADF\t\tTelenet: `c delphi', or 617/576-0862\n");
  86.      printf("\tuucp\tthad\t\tUSENET ...!well!thad\n\n");
  87.  
  88.      printf("\033[1mBBS-JC\033[0m is `home base' and is available via ");
  89.      printf("PCPursuit's 408 node\n");
  90.       exit();
  91.    }
  92.  
  93.    if ((output = fopen(argv[1], "w")) == NULL) {
  94.       printf("Problem opening `%s' for output, aborted\n", argv[1]);
  95.       exit(20);
  96.    }
  97.    
  98.    printf("Number of points (3:200)= \033[33m"); scanf("%d", &points);
  99.  
  100.    if((points < 3) || (points > 200)) {
  101.       printf("\033[0mIncorrect number of points (%d), aborted\n", points);
  102.       fclose(output);
  103.       exit(20);
  104.    }
  105.  
  106.    printf("\033[0mEnter the surface color = \033[33m"); scanf("%d", &color);
  107.    abs_color = ( color >= 0) ? color : -color;    /* abs(color) */
  108.    for(i = 0; i <= 48; i++) {
  109.       if (abs_color == valid_colors[i]) break;
  110.       if (-1 == valid_colors[i]) {
  111.          printf("\033[0mInvalid color (%d), aborted\n", color);
  112.          fclose(output);
  113.          exit(20);
  114.       }
  115.    }
  116.    
  117. /* output 3DG1 header information
  118.  */
  119.    fprintf(output, "3DG1\n%d\n", points);
  120.  
  121. /* output the coordinates of each polygon vertex per:
  122.  *
  123.  *    x = cos(angle) * radius
  124.  *      y = 0
  125.  *      z = sin(angle) * radius
  126.  */
  127.    step = radians/(double)points;
  128.    angle = radians;
  129.  
  130.    for(i=0; i < points; i++) {
  131.       x = cos(angle) * radius;
  132.       z = sin(angle) * radius;
  133.       fprintf(output, "%f 0 %f\n", x, z);
  134.       angle = angle - step;
  135.    }
  136.  
  137. /* output the <number of vertices>,<vertex point(n)> ... , <polygon color>
  138.  */
  139.    fprintf(output, "%d ", points);
  140.    for(i=0; i < points; i++) fprintf(output, "%d ", i);
  141.    fprintf(output, "%d\n", color);
  142.  
  143. /* all done
  144.  */
  145.    fclose(output);
  146.    printf("\033[0mDone.\n");
  147.    exit(0);
  148. }
  149.